package com.ygqh.baby.service.impl;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminMaterialDetail;
import  com.ygqh.baby.mapper.AdminMaterialDetailMapper;
import  com.ygqh.baby.service.AdminMaterialDetailService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminMaterialDetailExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminMaterialDetailServiceImpl implements AdminMaterialDetailService{
	
	@Autowired
	private AdminMaterialDetailMapper adminMaterialDetailMapper;
	
	@Override
	public List<AdminMaterialDetail> find() {
		AdminMaterialDetailExample example = new AdminMaterialDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminMaterialDetailMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminMaterialDetailExample example = new AdminMaterialDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminMaterialDetailMapper.countByExample(example);
	}

	@Override
	public AdminMaterialDetail findById(Long id) {
		return adminMaterialDetailMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminMaterialDetail adminMaterialDetail) {
		return adminMaterialDetailMapper.insertSelective(adminMaterialDetail);
	}

	@Override
	public int update(AdminMaterialDetail adminMaterialDetail) {
		return adminMaterialDetailMapper.updateByPrimaryKeySelective(adminMaterialDetail);
	}

	@Override
	public ResultSet<AdminMaterialDetail> search(QueryInfo queryInfo,Long batchId,String contractCode) {
		List<AdminMaterialDetail>  list =  adminMaterialDetailMapper.selectSuper(queryInfo, batchId,contractCode);
		int count = adminMaterialDetailMapper.countSuper(batchId,contractCode);
		ResultSet<AdminMaterialDetail> resultSet = new ResultSet<AdminMaterialDetail>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminMaterialDetailExample example = new AdminMaterialDetailExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminMaterialDetail record = new AdminMaterialDetail();
		record.setStatus(DataStatus.Delete);

		return adminMaterialDetailMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminMaterialDetail adminMaterialDetail) {
		int r = 0;
		if(adminMaterialDetail.getId() != null) {
			r = this.update(adminMaterialDetail);
		}else {
			r = this.save(adminMaterialDetail);
		}
		return r;
	}

	@Override
	public void saveBatchMaterialDetail(List<AdminMaterialDetail> adminMaterial) {
		adminMaterialDetailMapper.saveBatchMaterialDetail(adminMaterial);
		
	}

	@Override
	public List<AdminMaterialDetail> selectMaterialDetail(Long bathId,
			String contractCode) {
		return adminMaterialDetailMapper.selectMaterialDetail(bathId,contractCode);
	}
	

}

